package com.dream21th.flow.common.exception;

import com.dream21th.flow.common.ComResp;
import com.dream21th.flow.common.enums.RtnEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@ControllerAdvice
public class DevelopExceptionHandler {

    @ExceptionHandler({ RuntimeException.class })
    private ComResp runtimeException(RuntimeException e) {
        log.error("运行时异常{}", e);
        return new ComResp().fail(RtnEnum.INTERNAL_ERROR.getCode(),RtnEnum.INTERNAL_ERROR.getMessage());
    }

    @ExceptionHandler({ CommonException.class })
    private ComResp commonException(CommonException e) {
        log.error("自定义异常{}", e);
        return new ComResp().fail(e.getCode(),e.getMessage());
    }

    @ExceptionHandler({ IllegalStateException.class })
    private ComResp illegalStateException(IllegalStateException e) {
        log.error("自定义异常", e);
        return new ComResp().fail("500",e.getMessage());
    }
}
